<template>
  <div class="app-container">
    <el-form :model="form" label-width="110px" label-position="right">

      <el-row>
        <el-col :span="12">
          <el-form-item label=" 信息内容">
            <el-input
              v-model="form.mailMessage"
              type="textarea"
              :rows="5"
              placeholder="请填写 信息内容"
            />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="接收人id">
            <el-select v-model="form.mailStatus">
              <el-option label="未读" value="0" />
              <el-option label="已读" value="1" />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="6">
          <el-form-item>
            <el-button type="primary" @click="edit">{{ loadingText }}</el-button>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item>
            <router-link :to="`/siteMail/index`" style="margin-right: 5px">
              <el-button type="primary">取消</el-button>
            </router-link>
          </el-form-item>

        </el-col>
      </el-row>
    </el-form>
  </div>
</template>
<script>
import sysSiteMail from '@/api/siteMail'
export default {
  data() {
    return {
      form: {
        id: ''
      },
      loadingText: '保存'
    }
  },
  created() {
    const id = this.$route.params.id
    if (id) {
      this.form.id = id
      this.loadingText = '编辑'
      this.getDetailById(id)
    } else {
      this.loadingText = '保存'
    }
  },
  methods: {
    getDetailById(id) {
      sysSiteMail.getById(id).then(res => {
        this.form = res.data
      })
    },
    edit() {
      sysSiteMail.edit(this.form).then(res => {
        this.$message.success(res.message)
        this.$router.push('/siteMail/index')
      })
    }
  }
}
</script>
<style>

</style>
